package pl.edu.agh.gt.ga;

import java.util.HashMap;
import java.util.Map;

public class Genotype {

	Map<String,Object> genom = new HashMap<String,Object>();
	
	/*
	public void addGene(String name, Class clazz) throws InstantiationException, IllegalAccessException {
		genom.put(name, clazz.newInstance() );
	}
	*/
	
	public void addGeneFloat(String name) {
		genom.put(name, new Float(0) );
	}
	
	public void addGeneInt(String name) {
		genom.put(name, new Integer(0) );
	}
	
	public Object getGene(String name) {
		return genom.get(name);
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getGene(String name, Class<T> type) {
		return (T)genom.get(name);
	}
	
	public void setGene(String name, Object newValue) {
		assert genom.containsKey(name);
		genom.put(name, newValue);
	}
	
	public void setGene(String name, int newValue) {
		assert genom.containsKey(name);
		genom.put(name, new Integer(newValue));
	}
	
	public void setGene(String name, float newValue) {
		assert genom.containsKey(name);
		genom.put(name, new Float(newValue));
	}
	
	public Map<String, Object> getGenes() {
		return genom;
	}
	
	public String toString () {
		StringBuffer sb = new StringBuffer();
		for(String key : genom.keySet() )
			sb.append(key + "=" + genom.get(key) + " ");
		return sb.toString();
	}
	
	public boolean equals (Genotype g) {
		for(String key : this.genom.keySet() ) {
			if(!this.genom.get(key).equals(g.genom.get(key)))
				return false;
		}
		return true;
	}
}
